﻿
@{
    ViewBag.Title = "行政区域管理";
    Layout = "_Index";
}
<link href="~/plugins/jquery-treegrid/css/jquery.treegrid.min.css" rel="stylesheet" />
<link href="~/plugins/zTree_v3/css/bootstrapStyle/bootstrapStyle.css" rel="stylesheet" />
    <div class="ibox">
        <div class="row">
            <div class="col-sm-2">
                <div class="ibox ">
                    <ul id="pTree" class="ztree"></ul>
                </div>
            </div>
            <div class="col-sm-10">
                <div class="ibox ">
                    <div id="toolbar" class="btn-group">

                    </div>
                    <table id="areaTable"></table>
                </div>
            </div>
        </div>
    </div>

@section scripts
{
    <script src="~/plugins/zTree_v3/js/jquery.ztree.all.min.js"></script>
    <script src="~/plugins/bootstrapTableTree/bootstrap-table-treegrid.js"></script>
    <script src="~/plugins/jquery-treegrid/jquery.treegrid.min.js"></script>
    <script>
        var $table, $ptree;
        $(function () {
            loadpTree();
            loadGrid();
        });
        function loadpTree() {
            var opts = {

                data: {
                    simpleData: {
                        enable: true
                    }
                }, callback: {
                    onClick: DicZtreeClick

                }
            };
            jutils.ajaxGet('/admin/sysarea/getprovince', null, function (res) {
                $ptree = $.fn.zTree.init($("#pTree"), opts, res.data.list);
                $ptree.expandAll(true);
            });
        }
        //单击事件
        function DicZtreeClick(event, treeId, treeNode) {
            var pid = treeNode.id;

            $table.bootstrapTable('refresh', { query: { pid: pid } });

        }
        function loadGrid() {

            $table = $("#areaTable").bootstrapTable({
                url: '/admin/sysarea/GetData',
                height: $(window).height(),
                striped: true,
                sidePagination: 'server',
                idField: 'zipcode',
                columns: [
                    { field: 'ck', checkbox: true },
                    { field: 'name', title: '行政区域名称', align: 'left' },
                    { field: 'zipcode', title: '编码', align: 'center' }

                ],
                treeShowField: 'name',
                parentIdField: 'pid',
                onLoadSuccess: function (data) {
                    $table.treegrid({
                        // initialState: 'collapsed',
                        treeColumn: 1,
                        // expanderExpandedClass: 'glyphicon glyphicon-minus',
                        // expanderCollapsedClass: 'glyphicon glyphicon-plus',
                        onChange: function () {
                            $table.bootstrapTable('resetWidth');
                        }
                    });
                }
                // bootstrap-table-treetreegrid.js 插件配置
            });
            //jutils.initToolBar('#toolbar', true);
        }

        function add() {

            jutils.dialogForm('字典信息',
                '/admin/sysdic/formtest',
                null,
                function () {

                });
        }

        function edit() {
            var rows = $table.bootstrapTable('getSelections');
            if (rows.length === 1) {
                var pid = rows[0].parent_id;
                jutils.dialogForm('字典信息',
                    '/admin/sysdic/form',
                    { id: rows[0].id },
                    function () {
                        $table.bootstrapTable('refresh', { query: { pid: pid } });

                    });
            } else {
                jutils.warn('请选择一条需要编辑的数据行');
            }

        }

        function del() {
            var rows = $table.bootstrapTable('getSelections');
            if (rows.length === 0) {
                jutils.warn('请选中需要删除的数据行');
                return;
            }

            var ids = [];
            for (var i = 0; i < rows.length; i++) {

                ids.push(rows[i].id);

            }

            jutils.confirm('确认删除吗',
                function () {
                    jutils.ajaxGet('/admin/sysdic/del',
                        { ids: ids.join() },
                        function () {
                            $table.bootstrapTable('refresh');

                        });
                });
        }
    </script>


}
